#include "agreepro.h"
#include "ui_agreepro.h"
#include "root.h"
#include <vector>
#include "program.h"
#include "root.h"
#include <QMessageBox>
#include "bigsave.h"
extern vector <Program*> prdata;
int prbeg=-1;
int prend=-1;
int prnow=-1;
agreepro::agreepro(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::agreepro)
{
    ui->setupUi(this);
    unsigned int n = prdata.size();
       for(unsigned int i=0;i<n;i++){
          if( prdata[i]->showstatus()==3){
              ui->lineEdit->setText(prdata[i]->showid());
             prbeg = i;
             prnow = i;
             break;
          }
       }
       for(unsigned int i=prdata.size()-1;i>=0;i--){
           if(prdata[i]->showstatus()==3){
               prend = i;
               break;
           }
       }
}

agreepro::~agreepro()
{
    delete ui;
}

void agreepro::on_pushButton_4_clicked()
{
    this->close();
        root * p = new root;
        p->show();
}

void agreepro::on_pushButton_clicked()
{
    if(prnow==prbeg||prnow==0)
       {QMessageBox::information(this,"提示","这是第一个");}
       else {
           for(int i= prnow-1;i>=prnow;i--){
               if(prdata[i]->showstatus()==3){
                   prnow = i;
                   ui->lineEdit->setText(prdata[i]->showid());
                   break;
               }
           }
       }
}

void agreepro::on_pushButton_2_clicked()
{
    if(prnow==prend||prnow == prdata.size()-1){
            QMessageBox::information(this,"提示","这是最后一个");
        }else {
            for(int i= prnow+1;i<=prend;i++){
                if(prdata[i]->showstatus()==3){
                    prnow=i;
                    ui->lineEdit->setText(prdata[i]->showid());
                    break;
                }
            }
        }
}

void agreepro::on_pushButton_3_clicked()
{
    if(ui->radioButton->isChecked()==0&&ui->radioButton_2->isChecked()==0)
       {
           QMessageBox::information(this,"提示","请选择同意或不同意");
       }
       else if(ui->radioButton->isChecked()){
           prdata[prnow]->setstatus(0);
           this->close();
           bigsave();
           QMessageBox::information(this,"提示","同意申请成功");
           if(prbeg==prend){
               root *p = new root;
               p->show();
           }else{
               agreepro *p = new agreepro;
               p->show();
           }
       }
       else {
            QMessageBox::information(this,"提示","驳回申请成功");
           delete prdata[prnow];
           for(int i= prnow;i<prdata.size()-1;i++){
               prdata[i] = prdata[i+1];
           }
           this->close();
           prdata.pop_back();
           bigsave();
           if(prbeg==prend){
               root *p = new root;
               p->show();
           }else {
               agreepro *p = new agreepro;
               p->show();
           }
       }
}
